home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 24
/
Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso
/
Aminet
/
dev
/
c
/
AmiVoGL_MDEV.lha
/
drivers
/
X11.c
< prev
Wrap
C/C++ Source or Header
|
1994-04-12
|
22KB
|
1,161 lines
/*
* VOGL/VOGLE driver for X11.
*
* Define VOGLE if this driver is really for the VOGLE Libarary.
*
*/
#define VOGLE 1
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef VOGLE
#include "vogle.h"
static char *me = "vogle";
#define LARGEFONT "-adobe-courier-medium-r-normal--24-240-75-75-m-150-iso8859-1"
#define SMALLFONT "-adobe-courier-medium-r-normal--10-100-75-75-m-60-iso8859-1"
#else
#include "vogl.h"
static char *me = "vogl";
#define LARGEFONT "9x15bold"
#define SMALLFONT "6x13bold"
#endif
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define CMAPSIZE 256
#define EV_MASK KeyPressMask|ButtonReleaseMask|ExposureMask|ButtonPressMask
static int maxw = -1, maxh = -1;
static Window winder;
static Display *display;
static int screen;
static unsigned long carray[CMAPSIZE];
static Colormap colormap;
static Drawable theDrawable = -1;
static GC theGC;
static XGCValues theGCvalues;
static Pixmap bbuf; /* Back buffer pixmap */
static int back_used = 0; /* Have we backbuffered ? */
static XFontStruct *font_id = (XFontStruct *)NULL;
XEvent event;
static unsigned long colour;
static unsigned int h, w;
static char *smallf, *largef;
static char use_toolkit_win = 0;
/*
* vo_xt_set_win
*
* Just sets the drawable to the partucular window.
*/
int vo_xt_set_win(
Display *dis,
Drawable win,
int xw,
int xh)
{
int backb;
backb = (theDrawable == bbuf);
winder = win;
vdevice.sizeX = vdevice.sizeY = MIN(xh, xw);
vdevice.sizeSx = xw;
vdevice.sizeSy = xh;
if (xw > maxw || xh > maxh) {
if (back_used) {
back_used = 0;
XFreePixmap(display, bbuf);
X11_backbuf();
}
}
display = dis;
if (backb)
theDrawable = bbuf;
else
theDrawable = win;
return(1);
}
/*
* vo_xt_window
*
* Tells VOGL/VOGLE to use a window from an X11 toolkit (eg xview)
* and not to make it's own window.
*/
int vo_xt_window(
Display *dis,
Window win,
int xw,
int xh)
{
int backb, i, depth;
backb = (theDrawable == bbuf);
display = dis;
winder = win;
screen = DefaultScreen(display);
colormap = DefaultColormap(display, screen);
depth = vdevice.depth = DefaultDepth(display, screen);
theDrawable = winder;
use_toolkit_win = 1;
w = xw;
h = xh;
/*
* Set our standard colors...
*/
if (vdevice.depth == 1) {
/*
* Black and white - anything that's not black is white.
*/
carray[0] = BlackPixel(display, screen);
for (i = 1; i < CMAPSIZE; i++)
carray[i] = WhitePixel(display, screen);
} else {
/*
* Color, try to get our colors close to what's in the
* default colormap.
*/
X11_mapcolor(0, 0, 0, 0);
X11_mapcolor(1, 255, 0, 0);
X11_mapcolor(2, 0, 255, 0);
X11_mapcolor(3, 255, 255, 0);
X11_mapcolor(4, 0, 0, 255);
X11_mapcolor(5, 255, 0, 255);
X11_mapcolor(6, 0, 255, 255);
X11_mapcolor(7, 255, 255, 255);
}
if ((smallf = XGetDefault(display, me, "smallfont")) == (char *)NULL)
smallf = SMALLFONT;
if ((largef = XGetDefault(display, me, "largefont")) == (char *)NULL)
largef = LARGEFONT;
/*
* Create Graphics Context and Drawable
*/
theGC = XDefaultGC(display, screen);
theGCvalues.graphics_exposures = False;
theGCvalues.cap_style = CapButt;
XChangeGC(display, theGC, GCGraphicsExposures|GCCapStyle, &theGCvalues);
X11_color(0);
vdevice.sizeX = vdevice.sizeY = MIN(xh, xw);
vdevice.sizeSx = xw;
vdevice.sizeSy = xh;
if (back_used && (xw > maxw || xh > maxh)) {
back_used = 0;
XFreePixmap(display, bbuf);
X11_backbuf();
}
if (backb)
theDrawable = bbuf;
else
theDrawable = win;
#ifndef VOGLE
vdevice.devname = "X11";
#endif
return(1);
}
/*
* vo_xt_win_size
*
* If the X toolkit has changed the window size, then
* you might wish to call this routine to tell vogl/vogle about it.
*/
int vo_xt_win_size(
int xw,
int xh)
{
char backb;
w = xw;
h = xh;
vdevice.sizeX = vdevice.sizeY = MIN(h, w);
vdevice.sizeSx = w;
vdevice.sizeSy = h;
backb = (theDrawable == bbuf);
if (back_used) {
/* Have to re allocate the back buffer */
XFreePixmap(display, bbuf);
bbuf = XCreatePixmap(display,
(Drawable)winder,
(unsigned int)vdevice.sizeSx + 1,
(unsigned int)vdevice.sizeSy + 1,
(unsigned int)vdevice.depth
);
}
if (backb)
theDrawable = (Drawable)bbuf;
}
/*
* return the X display in use.
*/
Display * vo_xt_get_display(void)
{
return(display);
}
/*
* return the X Window in use.
*/
Window * vo_xt_get_window(void)
{
return(winder);
}
/*
* X11_init
*
* initialises X11 display.
*/
int X11_init(void)
{
int i;
int x, y, prefx, prefy, prefxs, prefys;
unsigned int bw, depth, mask;
Window rootw, childw;
char *av[2], name[128], *geom;
XSetWindowAttributes theWindowAttributes;
XWindowAttributes retWindowAttributes;
XSizeHints theSizeHints;
unsigned long theWindowMask;
XWMHints theWMHints;
if (use_toolkit_win)
return(1);
av[0] = me;
av[1] = (char *)NULL;
if ((display = XOpenDisplay((char *)NULL)) == (Display *)NULL) {
fprintf(stderr,"%s: X11_init: can't connect to X server\n", me);
exit(1);
}
screen = DefaultScreen(display);
winder = RootWindow(display, screen);
colormap = DefaultColormap(display, screen);
depth = vdevice.depth = DefaultDepth(display, screen);
/*
* Set our standard colors...
*/
if (vdevice.depth == 1) {
/*
* Black and white - anything that's not black is white.
*/
carray[0] = BlackPixel(display, screen);
for (i = 1; i < CMAPSIZE; i++)
carray[i] = WhitePixel(display, screen);
} else {
/*
* Color, try to get our colors close to what's in the
* default colormap.
*/
X11_mapcolor(0, 0, 0, 0);
X11_mapcolor(1, 255, 0, 0);
X11_mapcolor(2, 0, 255, 0);
X11_mapcolor(3, 255, 255, 0);
X11_mapcolor(4, 0, 0, 255);
X11_mapcolor(5, 255, 0, 255);
X11_mapcolor(6, 0, 255, 255);
X11_mapcolor(7, 255, 255, 255);
}
getprefposandsize(&prefx, &prefy, &prefxs, &prefys);
/*
* NEED TO USE XGRABPOINTER here???
*/
XQueryPointer(display, winder, &rootw, &childw, &x, &y, &x, &y, &mask);
if (childw == None)
childw = rootw;
/*
if (!XGetWindowAttributes(display, childw, &retWindowAttributes)) {
fprintf(stderr,"Can't get window attributes.");
exit(1);
}
x = retWindowAttributes.x;
y = retWindowAttributes.y;
w = retWindowAttributes.width;
h = retWindowAttributes.height;
bw = retWindowAttributes.border_width;
depth = vdevice.depth = retWindowAttributes.depth;
XTranslateCoordinates(display,
childw, retWindowAttributes.root,
0, 0,
&x, &y,
&rootw
);
*/
XGetGeometry(display, childw, &rootw, &x, &y, &w, &h, &bw, &depth);
theWindowAttributes.backing_store = WhenMapped;
theWindowAttributes.save_under = True;
theWindowAttributes.border_pixel = carray[1];
/*
* See if there is something in the .Xdefaults file regarding
* VOGL/VOGLE.
*/
if ((smallf = XGetDefault(display, me, "smallfont")) == (char *)NULL)
smallf = SMALLFONT;
if ((largef = XGetDefault(display, me, "largefont")) == (char *)NULL)
largef = LARGEFONT;
geom = XGetDefault(display, me, "Geometry");
if (geom != (char *)NULL) {
mask = XParseGeometry(geom, &x, &y, &w, &h);
if (mask & XValue)
theSizeHints.flags |= USPosition;
if (mask & YValue)
theSizeHints.flags |= USPosition;
if (mask & WidthValue)
theSizeHints.flags |= USSize;
if (mask & HeightValue)
theSizeHints.flags |= USSize;
if (mask & XNegative)
x = DisplayWidth(display, screen) - 2*bw - w + x;
if (mask & YNegative)
y = DisplayHeight(display, screen) - 2*bw - h + y;
} else
theSizeHints.flags = PPosition | PSize;
if (prefx > -1) {
x = prefx;
y = prefy;
}
if (prefxs > -1) {
w = prefxs;
h = prefys;
}
if (bw == 0)
bw = 4;
x -= bw;
y -= bw;
if (x <= 0)
x = 0;
if (y <= 0)
y = 0;
w -= 4 * bw;
h -= 4 * bw;
theWindowMask = CWBorderPixel|CWBackingStore;
winder = XCreateWindow(display,
winder,
x, y,